package com.yootk.filter;

import com.yootk.service.IMessageService;
import jakarta.servlet.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.context.support.WebApplicationContextUtils;

import java.io.IOException;

public class YootkMessageFilter implements Filter {
    private static final Logger LOGGER = LoggerFactory.getLogger(YootkMessageFilter.class) ;
    private IMessageService messageService ;
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        this.messageService = WebApplicationContextUtils.findWebApplicationContext(filterConfig.getServletContext()).getBean(IMessageService.class) ;
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        LOGGER.info("消息过滤：{}",this.messageService.echo("sunjava,张三"));
        chain.doFilter(request,response);
    }
}
